package beike;

import java.util.Scanner;

public class Third {

    public static int[] nums=new int[14];

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        String str=sc.next().toUpperCase();
        int count=0;
        for (int i = 0; i < str.length(); i++) {
            char c=str.charAt(i);
            if(c>='0'&& c<='9'){
                nums[c-'0']++;
            }else if(c=='A'){
                nums[1]++;
            }else if(c=='T'){
                nums[10]++;
            }else if(c=='J'){
                nums[11]++;
            }else if(c=='Q'){
                nums[12]++;
            }else if(c=='K'){
                nums[13]++;
            }
        }
        while (true){
            int max=0;
            int index=0;
            for (int i = 5; i < 14; i++) {
                int num=judge(i);
                if(num>max){
                    max=num;
                    index=i;
                }
            }
            if(max<5){
                break;
            }else{
                for (int i = 0; i < max; i++) {
                    nums[index-i]--;
                }
                count++;
            }
        }
        for (int i = 1; i < 14; i++) {
            int count1=0;
            if(nums[i]==4){
                nums[i]=0;
                count++;
                for (int j = 1; j < 14; j++) {
                    if(nums[j]==1 && count1<2){
                        nums[j]--;
                        count1++;
                    }
                }
                if(count1>0) {
                    break;
                }else {
                    for (int j = 1; j < 14; j++) {
                        if(nums[j]==2 ){
                            nums[j]=0;
                        }
                    }
                }
            }
        }
        for (int i = 1; i < 14; i++) {
            if(nums[i]==3){
                nums[i]=0;
                count++;
                for (int j = 1; j < 14; j++) {
                    if(nums[j]==1 ){
                        nums[j]--;
                        break;
                    }
                }
            }
        }
        for (int i = 1; i < 14; i++) {
            if(nums[i]!=0) count++;
        }
        count--;
        if(count==5) count=4;
        System.out.println(count);
    }
    public static int judge(int cur){
        int count=0;
        for(int i=cur;i>0;i--){
            if(nums[i]>0){
                count++;
            }else {
                return count;
            }
        }
        return count;
    }


}
//8K67A65K27T59K346AK2